package com.ruoyi.base.utils.serial;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * 序列号
 *
 * @author lcf
 */
public class SerialUtil {
    /**
     * 产生序列号
     */
    public static String getSerial() {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        StringBuilder result = new StringBuilder(format.format(new Date()));
        Random random = new Random();
        for (int i = 0; i < 5; i++) {
            result.append(random.nextInt(10));
        }
        return result.toString();
    }

    /**
     * 产生指定长度随机数
     */
    public static String getRandomNo(int num) {
        String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        char[] c = s.toCharArray();
        Random random = new Random();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < num; i++) {
            stringBuilder.append(c[random.nextInt(s.length())]);
        }

        return stringBuilder.toString();
    }
}
